package cn.sumpu.app.guoguojie.domain;

import java.io.Serializable;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

import cn.sumpu.app.guoguojie.domain.Ext.BonusView;
import cn.sumpu.app.guoguojie.util.Common;

public class Bonus implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6667563487128501359L;
	
	private String identifier; 
	private String name ;
	private String className;
	private String intro;
	private String applyReq;
	private String tryReq;
	private String endReq;
	private String fromUrl;
	private String applyStart;
	private String applyEnd;
	private String tryEnd;
	private Integer amount;
	private Integer leaveAmount;
	private Integer viewAmount;
	private Integer applyNums;
	private String imageServer;
	private String imageUrl;
	private String type;
	private Boolean enabled;
	private Date gmtCreated;
	private Date gmtModified;
	
	private List<Member> applyMember;
	
	
	public String getIdentifier() {
		return identifier;
	}
	public void setIdentifier(String identifier) {
		this.identifier = identifier;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getClassName() {
		return className;
	}
	public void setClassName(String className) {
		this.className = className;
	}
	public String getIntro() {
		return intro;
	}
	public void setIntro(String intro) {
		this.intro = intro;
	}
	
	public String getCutIntro(){
		return Common.cutStr(intro, 72, "...");
	}
	public String getApplyReq() {
		return Common.atContentRep2(applyReq);
	}
	public void setApplyReq(String applyReq) {
		this.applyReq = applyReq;
	}
	public String getFromUrl() {
		return fromUrl;
	}
	public void setFromUrl(String fromUrl) {
		this.fromUrl = fromUrl;
	}
	public String getApplyStart() {
		return applyStart;
	}
	public void setApplyStart(String applyStart) {
		this.applyStart = applyStart;
	}
	public String getApplyEnd() {
		return applyEnd;
	}
	public void setApplyEnd(String applyEnd) {
		this.applyEnd = applyEnd;
	}
	public String getTryEnd() {
		return tryEnd;
	}
	public void setTryEnd(String tryEnd) {
		this.tryEnd = tryEnd;
	}
	public Integer getAmount() {
		return amount;
	}
	public void setAmount(Integer amount) {
		this.amount = amount;
	}
	public Integer getViewAmount() {
		return viewAmount;
	}
	public void setViewAmount(Integer viewAmount) {
		this.viewAmount = viewAmount;
	}
	
	public Integer getApplyNums() {
		return applyNums;
	}
	public void setApplyNums(Integer applyNums) {
		this.applyNums = applyNums;
	}
	public String getImageServer() {
		return imageServer;
	}
	public void setImageServer(String imageServer) {
		this.imageServer = imageServer;
	}
	public String getImageUrl() {
		return imageUrl;
	}
	public void setImageUrl(String imageUrl) {
		this.imageUrl = imageUrl;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public Boolean getEnabled() {
		return enabled;
	}
	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}
	public Date getGmtCreated() {
		return gmtCreated;
	}
	public void setGmtCreated(Date gmtCreated) {
		this.gmtCreated = gmtCreated;
	}
	public Date getGmtModified() {
		return gmtModified;
	}
	public void setGmtModified(Date gmtModified) {
		this.gmtModified = gmtModified;
	}
	public String getTryReq() {
		return Common.atContentRep2(tryReq);
	}
	public void setTryReq(String tryReq) {
		this.tryReq = tryReq;
	}
	public List<Member> getApplyMember() {
		return applyMember;
	}
	public void setApplyMember(List<Member> applyMember) {
		this.applyMember = applyMember;
	}
	
	
	public Integer getLeaveAmount() {
		return leaveAmount;
	}
	public void setLeaveAmount(Integer leaveAmount) {
		this.leaveAmount = leaveAmount;
	}
	
	public String getEndReq() {
		return Common.atContentRep2(endReq);
	}
	public void setEndReq(String endReq) {
		this.endReq = endReq;
	}
	public BonusView getBonusView(){
	    if(Common.emptyStr(applyStart) || Common.emptyStr(applyEnd) || Common.emptyStr(tryEnd)){
	        return null;
	    }
		Date now = new Date(); 
		try {
			BonusView bv = new BonusView();
			Date applyS = Common.parseDate(applyStart, "yyyy-MM-dd HH:mm:ss");
			Date applyE = Common.parseDate(applyEnd, "yyyy-MM-dd HH:mm:ss");
			Date tryE = Common.parseDate(tryEnd, "yyyy-MM-dd HH:mm:ss");
			if(now.getTime() < applyS.getTime()){
				bv.setStatus(1);
				bv.setDefaultTime((int)(applyS.getTime() - now.getTime())/1000);
				return bv;//现在小于开始是件则未开始状态
			}else if(now.getTime() >= applyS.getTime() && now.getTime() <= applyE.getTime()){
				bv.setStatus(2);
				bv.setDefaultTime((int)(applyE.getTime() - now.getTime())/1000);
				return bv;//现在大于等于开始时间小于等于结束时间则开始状态
			}else if(now.getTime() > applyE.getTime() && now.getTime() < tryE.getTime()){
				bv.setStatus(3);
				bv.setDefaultTime((int)(tryE.getTime() - now.getTime())/1000);
				return bv;//现在大于申请时间小于试用结束时间则开始状态
			}else{
				bv.setStatus(4);
				return bv;
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
}

